package cn.book.book.service;

import cn.book.book.domain.Author;
import cn.book.book.mapper.AuthorMapper;

import cn.book.book.vo.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
@Service
public class AuthorService {
    @Autowired
    private AuthorMapper authorMapper;

    public int add(Author a){
        return authorMapper.add(a);
    }
    public Author get(Long id){
        return authorMapper.get(id);
    }
    public int update(Author a){
        return authorMapper.update(a);
    }

    public int delete(Long id){
        return authorMapper.delete(id);
    }
    public Page<Author> selectList(int pageNum, int pageSize, Author a){
        com.github.pagehelper.Page<Author> p = PageHelper.startPage(pageNum, pageSize);
        List<Author> authors = this.authorMapper.selectList(a);
        return new Page(p.getPageNum(),p.getPageSize(),p.getTotal(),p.getPages(),authors);
    }
    @Transactional//保证在一个事务内完成
    public int batchDel(Long[] ids) {

        //authorMapper.batchDel(ids);

        int r=0;
        for(Long id:ids){
            r+=this.authorMapper.delete(id);
        }
        return r;
    }
}
